import Vue from 'vue'
import FastClick from 'fastclick'
import { sync } from 'vuex-router-sync'
import VueLazyload from 'vue-lazyload'
import App from './App'
import store from './store'
import router from './router'
import utils from 'src-common/utils'
import * as types from 'src-store/types'
import filters from 'src-common/filters'
import components from 'src-components'

// 注册全局 - 过滤器
Object.keys(filters).forEach(k => Vue.filter(k, filters[k]))

// 注册全局 - 组件
Object.keys(components).forEach(c => Vue.component(c, components[c]))

// 注册全局 - mutations-types
Vue.prototype.$$types = types
// Vue.use({ install (Vue, options) { Vue.prototype['$$types'] = types } })

// 注册全局 - 工具类
Vue.prototype.$$utils = utils
// Vue.use({ install (Vue, options) { Vue.prototype['$$utils'] = utils } })

// 同步路由信息至store (通过store.state.route.params获取信息)
sync(store, router)

FastClick.attach(document.body)

Vue.use(VueLazyload)

// image lazyload
Vue.use(VueLazyload, {
  preLoad: 1.3,
  error: require('./assets/img/error.svg'),
  loading: require('./assets/img/loading.svg'),
  attempt: 1,
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App },
})
